import time
from queue import Queue
from threading import Thread

url_list=[f'https://www.baidu.com-{i}' for i in range(20)]

def work():
    while url_list:
        url=url_list.pop()
        print(url)
        time.sleep(0.5)

def main():
    s_t = time.time()
    t1 = Thread(target=work)
    t1.start()
    t2 = Thread(target=work)
    t2.start()
    t3 = Thread(target=work)
    t3.start()
    t4 = Thread(target=work)
    t4.start()
    t1.join()
    t2.join()
    t3.join()
    t4.join()
    e_t = time.time()
    print("运行时间：", e_t - s_t)

def main2():
    s_t = time.time()
    ts=[]
    for i in range(4):
        t=Thread(target=work)
        t.start()
        ts.append(t)
    for t in ts:
        t.join()
    e_t = time.time()
    print("运行时间：", e_t - s_t)


q = Queue()
for i in url_list:
    q.put(i)
def work1():
    while not q.empty():
        a=q.get()
        time.sleep(0.5)
        print(a)
def main3():
    s_t = time.time()
    ts=[]
    for i in range(4):
        t=Thread(target=work1)
        t.start()
        ts.append(t)
    for t in ts:
        t.join()
    e_t = time.time()
    print("运行时间：", e_t - s_t)

if __name__ == '__main__':
    # main()
    # main2()
    main3()